#!/bin/bash

if [[ $# -lt 1 ]]; then
    lsb_release  -a 2> /dev/null || true
    echo
    echo "Usage: $(basename $0) <src_file>"
    exit 1
fi

src_file=$1

set -e

if [[ ! -f ${src_file} ]]; then
    echo "No such file or directory: ${src_file}"
    exit 1
fi

if [[ ! -f /etc/apt/sources.list.bak ]]; then
    mv /etc/apt/sources.list /etc/apt/sources.list.bak
fi

cat ${src_file} > /etc/apt/sources.list

# to change apt source, ca-certificate must be installed
# update and install other packages
# apt-get -o Acquire::https::Verify-Peer="false"
echo "Acquire { https::Verify-Peer false }" > /etc/apt/apt.conf.d/99verify-peer.conf
apt-get update
apt-get install -y ca-certificates
rm -f /etc/apt/apt.conf.d/99verify-peer.conf
apt-get update
apt-get install --reinstall -y apt-utils ca-certificates

